<?php 
	include "../../config.php";
	include ADMIN_ROOT."templates/header.php";
	require_once DOC_ROOT."lib/connection.php";
	include DOC_ROOT."/lib/ckeditor/ckeditor.php";
	include DOC_ROOT."/lib/ckfinder/ckfinder.php";
?>
<div id="main-content">
<?php 
		$stmt = sqlsrv_query($con,"SELECT product_id,product_name,product_description,unit_size,unit_price, picture FROM product");
		$page = 1;
    if(isset($_GET['page'])){
      $page = $_GET['page'];  
    }   
    $row_per_page = 10;
    $start = ($page-1)* $row_per_page;
    $end = $page * $row_per_page;
?>
  <div class="heading">
      <h1>Products</h1>
      <div class="buttons"><a onclick="location = 'http://demo.opencart.com/admin/index.php?route=catalog/product/insert&amp;token=d80fcd5cb6064f0b3a5d7c1011828837'" class="button">Insert</a><a onclick="$('#form').attr('action', 'http://demo.opencart.com/admin/index.php?route=catalog/product/copy&amp;token=d80fcd5cb6064f0b3a5d7c1011828837'); $('#form').submit();" class="button">Delete</a></div>
  </div>
	<table class="list">
    <?php
      $sql= sqlsrv_query($con,"SELECT * FROM(SELECT row_number() over(order by product_id desc) as row, p.* FROM product p) as a WHERE row between $start AND $end");
      $sql1 = sqlsrv_query($con,"SELECT count(*) from product");
      sqlsrv_fetch($sql1);
      $tong = sqlsrv_get_field($sql1,0);
      $sotrang = ceil($tong/$row_per_page);
      while(sqlsrv_fetch($sql)){
        $id = sqlsrv_get_field($sql,0);
  ?>
        <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);"></td>
              <!-- <td class="center">Image</td> -->
              <td class="left"><a href="#" class="asc">Product Name</a>
                </td>
              <td class="left"><a href="#">Description</a>
                </td>
              <td class="left"><a href="#">Price</a>
                </td>
              <td class="right"><a href="#">Quantity</a>
                </td>
              <td class="left"><a href="#">Status</a>
                </td>
              <td class="right">Action</td>
            </tr>
        </thead>
        <?php 
          while(sqlsrv_fetch($stmt)){
          $id=sqlsrv_get_field($stmt,0);
        ?>
        <tbody>
            <tr>
              <td style="text-align: center;"><input type="checkbox" name="selected[]" value="42">
                </td>
              <!-- <?php 
              echo "<td class='center'><img src='images/product/";
              ?>
              <?php 
              echo "sqlsrv_get_field($stmt,5)' alt='Apple Cinema 30&quot;' style='padding: 1px; border: 1px solid #DDDDDD;'></td>"; 
              ?>
            -->
              <td class="left"><?=sqlsrv_get_field($stmt,1)?></td>
              <td><?=sqlsrv_get_field($stmt,2)?></td>
              <td><?=sqlsrv_get_field($stmt,4)?></td>
              <td class="right"><span style="color: #008000;">691</span>
                </td>
              <td class="left">Enabled</td>
              <td class="right">
                [ <a href="<?=ADMIN_URL?>products/edit.php?id=<?=$id?>">Edit</a>&nbsp;]
                [ <a href="javascript:warning('<?=ADMIN_URL?>products/del.php','<?=$id?>')">Del</a> ]
              </td>
            </tr>
            <?php
              }
              sqlsrv_free_stmt($stmt);
              sqlsrv_close($con);
            ?>
        </tbody>
     </table>
     <?php }?>
     <p> <a href="<?=ADMIN_URL?>views/products/add.php"> Add product </a></p>
     <div class="page">
          <?php
            for($i=1;$i<$sotrang+1;$i++){
          ?>
              <a href="<?=URL_ROOT?>index.php?page=<?=$i?>">[<?=$i?>]</a>
            <?php   
              }
          ?>
        </div><!-- END wrap-content -->
</div>
</div><!-- END main-content -->
</div><!-- END wrap-content -->
</div><!-- END content -->
			
<?php
	include ADMIN_ROOT."templates/footer.php";
?>